//
// fake_server.cpp
// ~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2010 The bufdb Team
//

#include <ctime>
#include <iostream>
#include <string>
#include <boost/asio.hpp>

#include "database.pb.h"

#include <google/protobuf/message.h>
using namespace google::protobuf;
using boost::asio::ip::tcp;

int main(int argc, char *argv[])
{
  try
  {
    boost::asio::io_service io_service;

    tcp::endpoint endpoint(tcp::v4(), 13);
    tcp::acceptor acceptor(io_service, endpoint);

    for (;;)
    {
      tcp::iostream stream;
      acceptor.accept(*stream.rdbuf());

      // parse the message into the class
      db::Database *msg = new db::Database();
      if (!msg->ParseFromIstream(&stream)) {
        std::cerr << "Failed to parse" << std::endl;
        exit(1);
      }

      msg->PrintDebugString();
      cout << endl;
      break;
    }
  }
  catch (std::exception& e)
  {
    std::cerr << e.what() << std::endl;
  }

  return 0;
}

